<template>
    <el-form :inline="true" :model="formInline">
        <el-form-item label="设备名称">
            <el-input v-model="formInline.user" placeholder="请输入设备名称查询" clearable />
        </el-form-item>
        <el-form-item label="通讯状态">
            <el-select v-model="formInline.region" placeholder="请选择通讯状态" clearable>
                <el-option label="正常" value="0" />
                <el-option label="异常" value="1" />
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="search">搜索</el-button>
            <el-button type="primary" size="default" @click="reset">重置</el-button>
        </el-form-item>
    </el-form>
    <div class="alert">
        <div class="alert-Content">
            <div class="alert-left">
                <el-icon :size="20" color="#409EFC">
                    <WarningFilled />
                </el-icon>
                异常设备:<span class="red-text">0</span>
            </div>
            <div class="alert-right">
                <el-icon :size="20" color="#409EFC">
                    <Refresh />
                </el-icon>
                刷新
            </div>
        </div>
    </div>
    <div class="mt15">
        <el-table :data="storageData" border>
            <el-table-column prop="storageName" label="设备名称"></el-table-column>
            <el-table-column prop="storageStatus" label="设备状态"></el-table-column>
            <el-table-column prop="storagePower" label="功率（W）"></el-table-column>
            <el-table-column prop="storageVoltage" label="电压（V）"></el-table-column>
            <el-table-column prop="storageCurrent" label="电流（A）"></el-table-column>
            <el-table-column prop="storageTemperature" label="温度（℃）"></el-table-column>
            <el-table-column prop="updateTime" label="更新时间"></el-table-column>
            <el-table-column label="操作">
                <template #default="{ row }">
                    <el-button type="text" @click="showDrawer(row)">详情</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
    <el-drawer v-model="drawerVisible" :size="900">
        <template #header>
            <h4>查看详情</h4>
        </template>
        <!-- 身体部分 -->
        <template #default>
            <div style="height: 300px;">
                <!-- <el-chart :options="chartOptions" style="height: 100%;"></el-chart> -->
                <img src="@/assets/images/echart.png" />
            </div>
        </template>
        <template #footer>
            <div style="flex: auto">
                <el-button @click="cancel">取消</el-button>
                <!-- <el-button type="primary" @click="save">确定</el-button> -->
            </div>
        </template>
    </el-drawer>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'

const formInline = reactive({
    user: '',
    region: '',
})
const search = () => {
    console.log('submit!')
}
//重置按钮
const reset = () => {
}
interface StorageData {
    storageName: string;
    storageStatus: string;
    storagePower: number;
    storageVoltage: number;
    storageCurrent: number;
    storageTemperature: number;
    updateTime: string;
}

const storageData = ref<StorageData[]>([
    {
        storageName: '储能设备1',
        storageStatus: '运行中',
        storagePower: 20,
        storageVoltage: 220,
        storageCurrent: 2,
        storageTemperature: 35,
        updateTime: '2022-01-01 12:00:00',
    },
    // 可以添加更多的储能设备数据
]);

const drawerVisible = ref(false);
// const currentStorage = ref<StorageData | null>(null);

const showDrawer = (row: StorageData) => {
    // currentStorage.value = row;
    drawerVisible.value = true;
};

const chartOptions = ref({
    // 这里是echarts图表的配置项
});
//取消按钮的回调
const cancel = () => {
    //关闭抽屉
    drawerVisible.value = false;
}
</script>

<style scoped lang="scss"></style>